# Maintainer: Hristiyan Ivanov <hristiyan.d.ivanov@gmail.com>
pkgname=spacectl
pkgver=0.30.0
pkgrel=2
pkgdesc="A Utility wrapping Spacelift's GraphQL API for easy programmatic access in command-line contexts."
url="https://github.com/spacelift-io/spacectl"
arch="all"
license="MIT"
makedepends="go"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/spacelift-io/spacectl/archive/refs/tags/v$pkgver.tar.gz"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

prepare() {
	default_prepare
	go mod download
}

build() {
	go build .

	for shell in bash fish zsh; do
		./spacectl completion $shell > spacectl.$shell
	done
}

check() {
	go test ./...
}

package() {
	install -Dm0755 spacectl -t "$pkgdir"/usr/bin/

	install -Dm0644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/

	install -Dm0644 spacectl.bash \
		"$pkgdir"/usr/share/bash-completion/completions/spacectl
	install -Dm0644 spacectl.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/spacectl.fish
	install -Dm0644 spacectl.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_spacectl
}

sha512sums="
6780dfe4dd3cbc15a202f0d5f596e9aca983b9e30ede9d2969d16a1960f4ad71e9ce52caec3a612a10632d154297aee75bd37f7efc873bd7d4dea6d3f47b422b  spacectl-0.30.0.tar.gz
"
